﻿/* 7. Write a program that reads a number N and calculates the sum of the first N members of the sequence of Fibonacci: 
 * 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ... 
 * Each member of the Fibonacci sequence (except the first two) is a sum of the previous two members. */

// Add Reference to 'System.Numerics'.

using System;
using System.Numerics;

public class SumOfFibonacciMembers
{
    public static void Main()
    {
        BigInteger first = 0;
        BigInteger second = 1;
        int n;
        BigInteger sum = 0;

        do
        {
            Console.Clear();
            Console.Write("N = ");
            if ((int.TryParse(Console.ReadLine(), out n)) && (0 < n))
                break;
        } while (true);

        for (int step = (n + 1) / 2 - 1; step > 0; step--)
        {
            sum += first + second;
            first += second;
            second += first;
        }

        sum += first;
        if ((1 | n) != n)
            sum += second;

        Console.WriteLine("The Sum is {0}", sum);
    }
}